//
//  Brand.m
//  CarTown
//
//  Created by xionghao on 15/9/10.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "Brand.h"
#import <MJExtension.h>
#import "AppDelegate.h"
@implementation Brand

@dynamic brand_name;
@dynamic brand_logo;
@dynamic brand_desc;
@dynamic brand_id;
+(void)addBrand:(NSArray *)data{
    AppDelegate *delegate=[[UIApplication sharedApplication]delegate];
    
    [Brand objectArrayWithKeyValuesArray:data context:delegate.managedObjectContext];
    [delegate saveContext];

}
+(instancetype)getbarndByName:(NSString *)name{
    AppDelegate *delegate=[[UIApplication sharedApplication]delegate];
    NSFetchRequest *request=[NSFetchRequest fetchRequestWithEntityName:@"Brand"];
    NSPredicate *pre=[NSPredicate predicateWithFormat:@"brand_name = %@",name];
    request.predicate=pre;
    NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"brand_desc" ascending:YES];
    request.sortDescriptors=@[sort];
    NSArray *sets= [delegate.managedObjectContext executeFetchRequest:request error:nil];
    if (sets.count>0) {
        return sets[0];
    }else{
    return nil;
    }
}
+(NSArray *)getBrand{
    AppDelegate *delegate=[[UIApplication sharedApplication]delegate];
    NSFetchRequest *request=[NSFetchRequest fetchRequestWithEntityName:@"Brand"];
    
    NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"brand_desc" ascending:YES];
    request.sortDescriptors=@[sort];
    NSArray *sets= [delegate.managedObjectContext executeFetchRequest:request error:nil];
    return sets;

}
@end
